package com.jumi.microservice.controller;

import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.config.UserCashConfig;
import com.jumi.microservice.dto.usercash.TypeListResponse;
import com.jumi.microservice.dto.usercash.api.*;
import com.jumi.microservice.service.UserCashService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author scw
 * @since 2020-07-21
 */
@Api(tags = {"C端--提现管理相关接口"})
@RestController
@RequestMapping("/api/userCash")
public class UserCashController extends BaseController {
    @Resource
    private UserCashService userCashService;

    @GetMapping("/userCashList")
    @ApiOperation("提现列表")
    TableDataInfo<UserCashApiListResponse> userCashList(UserCashApiListRequest userCashApiListRequest) {
        //获取当前用户ID
        userCashApiListRequest.setUid(getApiUserId().longValue());
        return userCashService.userCashList(userCashApiListRequest);
    }

    @GetMapping(value = "/userCashDetail")
    @ApiOperation("提现详情")
    public ResponseResult<UserCashApiDetailResponse> userCashDetail(UserCashApiDetailRequest userCashApiDetailRequest) {
        ResponseResult<UserCashApiDetailResponse> result = new ResponseResult<>();
        //获取当前用户ID
        userCashApiDetailRequest.setUid(getApiUserId().longValue());
        UserCashApiDetailResponse userCashApiDetailResponse = userCashService.userCashDetail(userCashApiDetailRequest);
        result.setData(userCashApiDetailResponse);
        return result;
    }

    @PostMapping(value = "/addUserCash")
    @ApiOperation("申请提现")
    public ResponseResult<Boolean> addUserCash(UserCashApiAddRequest userCashApiAddRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        //获取当前用户ID
        userCashApiAddRequest.setUid(getApiUserId().longValue());
        result.setData(userCashService.addUserCash(userCashApiAddRequest));
        return result;
    }

    @GetMapping("/cashType/dictionary")
    @ApiOperation("提现账户类型对照字典")
    public ResponseResult<List<TypeListResponse>> getCashType() {
        ResponseResult<List<TypeListResponse>> result = new ResponseResult<>();
        result.setData(userCashService.getCashType());
        return result;
    }

    @GetMapping("/status/dictionary")
    @ApiOperation("提现状态对照字典")
    public ResponseResult<List<TypeListResponse>> getStatus() {
        ResponseResult<List<TypeListResponse>> result = new ResponseResult<>();
        result.setData(userCashService.getStatus());
        return result;
    }

    @PostMapping(value = "/amountLimit")
    @ApiOperation("提现相关限额")
    public ResponseResult<AmountLimitResponse> amountLimit() {
        ResponseResult<AmountLimitResponse> result = new ResponseResult<>();
        result.setData(userCashService.amountLimit(getApiUserId().longValue()));
        return result;
    }
}

